package com.fcscs.cservice.client.common.controller;

import java.util.Date;
import java.util.List;

import com.fcscs.core.common.MainPaginationSearchModel;
import com.fcscs.core.common.SearchResultsContainer;
import com.fcscs.core.gwt.common.AsyncCallbackListener;
import com.fcscs.core.gwt.common.GWTAsyncCaller;
import com.fcscs.cservice.client.common.CServiceTimeUtils;
import com.fcscs.cservice.domain.ExpressCheckInConfig;
import com.fcscs.cservice.domain.model.CheckInConfiguration;
import com.fcscs.cservice.domain.model.CheckOutConfiguration;
import com.fcscs.cservice.domain.model.FolioView;
import com.fcscs.cservice.domain.model.MessageView;
import com.fcscs.cservice.domain.model.RCView;
import com.fcscs.cservice.domain.model.ReservationConf;
import com.fcscs.cservice.domain.model.ReservationView;
import com.fcscs.cservice.gwt.client.ReservationService;
import com.fcscs.cservice.gwt.client.ReservationServiceAsync;
import com.google.gwt.core.client.GWT;

public class ReservationServiceController extends GWTAsyncCaller {
    private static ReservationServiceController INSTANCE = new ReservationServiceController();
    private ReservationServiceAsync reservationServiceGWT = GWT.create(ReservationService.class);
    
    public static ReservationServiceController getINSTANCE(){
    	return INSTANCE;
    } 
    
    private ReservationServiceController(){
    }
    
    public void findReservations(Long rsvStatusId, 
    		MainPaginationSearchModel sm, AsyncCallbackListener<SearchResultsContainer<ReservationView>> callback){
    	Date startTime = CServiceTimeUtils.setDateStartTime(new Date());
    	Date endTime = CServiceTimeUtils.setDateEndTime(new Date());
    	reservationServiceGWT.findReservations(sm.getSearchTerm(), rsvStatusId, startTime, endTime, sm.getStart(), sm.getResultsPerPage(), createCallBack(0, callback));
    }
    
    public void findReservations(String firstName, String lastName, Long rsvStatus, String roomNo, 
			String memberNo, Long roomStatus, String baggageNo, Date arrivDate, Date departDate, Date eta, 
			Date etd, Date date, MainPaginationSearchModel sm, AsyncCallbackListener<SearchResultsContainer<ReservationView>> callback){
    	arrivDate = CServiceTimeUtils.resetFindDate(arrivDate, eta);
    	departDate = CServiceTimeUtils.resetFindDate(departDate, etd);
    	reservationServiceGWT.findReservations(firstName, lastName, rsvStatus, 
    		roomNo, memberNo, roomStatus, baggageNo, arrivDate, departDate, eta, 
    		etd, date,sm.getStart(), sm.getResultsPerPage(), createCallBack(0, callback));
    }
    
    public void findRsvForFolio(String firstName, String lastName,
			Long rsvStatusId, String roomNo, Date arrivStart, Date arrivEnd,
			Date departStart, Date departEnd, Date date, MainPaginationSearchModel sm,
			AsyncCallbackListener<SearchResultsContainer<ReservationView>> callback){
    	reservationServiceGWT.findRsvForFolio(
    			firstName, lastName, rsvStatusId, roomNo, arrivStart, 
    			arrivEnd, departStart, departEnd, date, sm.getStart(), sm.getResultsPerPage(), 
    			createCallBack(0, callback));
    }

    public void getMessages(long rsvId, AsyncCallbackListener<List<MessageView>> callback){
    	reservationServiceGWT.getMessages(rsvId, createCallBack(0, callback));
    }
    
    public void getFolioView(long id, AsyncCallbackListener<FolioView> callback){
    	reservationServiceGWT.getFolioView(id, createCallBack(0, callback));
    }
    
    public void getRCView(long id, AsyncCallbackListener<RCView> callback){
    	reservationServiceGWT.getRCView(id, createCallBack(0, callback));
    }
    
    public void updateRC(RCView rc, AsyncCallbackListener<RCView> callback){
    	reservationServiceGWT.updateRC(rc, createCallBack(0, callback));
    }


	public void getRsvConf(long propId, AsyncCallbackListener<ReservationConf> callback) {
		reservationServiceGWT.getRsvConf(propId, createCallBack(0, callback));
	}

	public void saveRsvConf(ReservationConf conf, AsyncCallbackListener<ReservationConf> callback) {
		reservationServiceGWT.saveRsvConf(conf, createCallBack(0, callback));
	}

	public void getCheckInConf(long propId, AsyncCallbackListener<CheckInConfiguration> callback) {
		reservationServiceGWT.getCheckInConf(propId, createCallBack(0, callback));
	}


	public void getCheckOutConf(long propId, AsyncCallbackListener<CheckOutConfiguration> callback) {
		reservationServiceGWT.getCheckOutConf(propId, createCallBack(0, callback));
	}

	public void saveCheckOutConf(CheckOutConfiguration conf, AsyncCallbackListener<CheckOutConfiguration> callback) {
		reservationServiceGWT.saveCheckOutConf(conf, createCallBack(0, callback));
	}
}
